import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;
interface IntegerStack{
	public Integer push(Integer item);//如item为null，则不入栈直接返回null。如栈满，也返回null.
	public Integer pop();//出栈，如为空，则返回null.
	public Integer peek();//获得栈顶元素，如为空，则返回null.
	public boolean empty();//如为空返回true
	public int size();//返回栈中元素数量
}
public class Main {
	public static void main(String[] args) {
		Scanner a = new Scanner(System.in);
		ArrayListIntegerStack stack = new ArrayListIntegerStack();
		int m = a.nextInt();
		for (int i = 0; i < m; i++) {
			System.out.println(stack.push(a.nextInt()));
		}
		System.out.print(stack.peek() + "," + stack.empty() + "," + stack.size() + "\n");
		System.out.println(Arrays.toString(stack.getStack()));
		int x = a.nextInt();
		for (int i = 0; i < x; i++) {
			System.out.println(stack.pop());
		}
		System.out.print(stack.peek() + "," + stack.empty() + "," + stack.size() + "\n");
		System.out.println(Arrays.toString(stack.getStack()));
		a.close();
	}
}
class ArrayListIntegerStack implements IntegerStack {
	private List<Integer> list;
	public ArrayListIntegerStack(){
	   list = new ArrayList<Integer>();
	}
	
    public Integer push(Integer item) {
		if (item == null)	
		return null;
		list.add(item);
		//top++;
		return item;          
	}

	public Integer pop() {
		if(list.size()==0)
			return null;
		return list.remove(list.size()-1);
	}

	public Integer peek() {
		if(list.size()==0)
			return null;
			return list.get(list.size()-1);
	}

	public boolean empty() {
		return list.size()==0?true:false;
	}

	public int size() {
		return list.size();
	}

	public  Integer[] getStack(){
		Integer[] a=(Integer[])list.toArray(new Integer[list.size()]);
		return a;
	}
	public String toString(){
		return list.toString();
	}
}